package com.eastfair.messagecenter.callable;

import com.eastfair.core.exception.MessageBizException;
import com.eastfair.messagecenter.pipeline.ProcessContext;
import com.eastfair.messagecenter.pipeline.ProcessController;

import java.util.concurrent.Callable;

public class SendTask implements Callable<String> {
    private ProcessContext context;
    private ProcessController processController;

    public SendTask(ProcessContext context, ProcessController processController) {
        this.context = context;
        this.processController = processController;
    }

    /**
     * 任务的具体过程，一旦任务传给ExecutorService的submit方法，则该方法自动在一个线程上执行。
     *
     * @return
     * @throws Exception
     */
    @Override
    public String call() throws MessageBizException {
        //启动责任链
        ProcessContext process = processController.process(context);

        return "发送 call()方法被自动调用，任务的结果是：OK";
    }
}